package utils;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.window.IShellProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import data.ShowData;

public class SageShowDialog extends Dialog
{
    private ShowData _data = null;
    private Text _fileName;
    
    public SageShowDialog(IShellProvider parentShell, ShowData data)
    {
        super(parentShell);
        _data = data;
    }
    
    @Override
    protected Control createDialogArea(Composite parent)
    {
        Composite cmp = new Composite(parent, SWT.None);
        cmp.setLayout(new GridLayout(2, false));
        Label showName = new Label(cmp, SWT.None);
        showName.setText("name:");
        Label name = new Label(cmp, SWT.None);
        name.setText(_data.getTitle());
        Label fileNamelab = new Label(cmp, SWT.None);
        fileNamelab.setText("filename:");
        _fileName = new Text(cmp, SWT.None);
        _fileName.setText(_data.getFileName());
        return cmp;
    }
    
    @Override
    protected void createButtonsForButtonBar(Composite parent)
    {
        // TODO Auto-generated method stub
        super.createButtonsForButtonBar(parent);
        
        createButton(parent, IDialogConstants.RETRY_ID,
                "Refresh", true);
    }

    @Override
    protected void buttonPressed(int buttonId)
    {
        super.buttonPressed(buttonId);
        switch (buttonId)
        {
        case IDialogConstants.RETRY_ID:
            ShowData data = SageTvShows.getInstance().renameFileNameInShow(_data.getShowId());
            if (data != null)
            {
                _data = data;
                refreshScreen();
            }
            
            break;        
        }
        
    }

    private void refreshScreen()
    {
        _fileName.setText(_data.getFileName());
    }
}
